package com.pospi.pospihold.print;

import android.content.Context;
import android.graphics.Bitmap;

import com.pospi.pospihold.dto.OrderBeen;
import com.pospi.pospihold.sprint.StarPrintHelper;
import com.ums.AppHelper;

import java.io.FileOutputStream;

public class UnionPrint {
    private Context context;

    public UnionPrint(Context context) {
        this.context = context;
    }
    public void print(final OrderBeen orderBeen){
        new Thread(new Runnable() {
            @Override
            public void run() {
//                if (App.IsPrinter) {// 如果打印机可用
//                    if (Build.MODEL.equals(Model.A920)) {
//                        PrintA920.prnVoucher(getApplicationContext(), orderBeen);
//                    } else {
//
//                    }
//                }
                Bitmap bitmap = StarPrintHelper.creatImageOrder(orderBeen, context);
                printTest(bitmap);
            }
        }).start();
    }
    /**
     * 交易结果打印*/
    private void printTest(Bitmap bitmap){
        if(bitmap == null){
            return;
        }

        String fname = "/sdcard/ddd.png";
        try {
            FileOutputStream out = new FileOutputStream(fname);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        AppHelper.callSyncPrint(context, fname);

    }
}
